//
//  JSMDetailsPictureViewController.m
//  TakeYouTourTogether
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDetailsPictureViewController.h"
#import "JSMTouringDetailModel.h"

@interface JSMDetailsPictureViewController ()
@property(nonatomic, strong)BaseScrollView *photoView;
@property(nonatomic, strong)NSMutableArray *detailArr;
@end

@implementation JSMDetailsPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.title = self.titleStr;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"<<" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    [self createPhotoView];
    [self createDate];
}
#pragma mark 解析数据
- (void)createDate{
    [AFNetworkingTool getUrl:self.strURL hudSuperView:self.view result:JSON success:^(id result) {
        NSMutableDictionary *dic = result;
        self.detailArr = [JSMTouringDetailModel baseModelByArr:dic[@"log"][@"posts"]];
        [self createPhoto];
    } failure:^(NSError *error) {
        
        
    }];
}
- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 创建相册
- (void)createPhotoView{
    self.photoView = [[BaseScrollView alloc]init];
    [self.view addSubview:self.photoView];
    [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.view);
        make.width.mas_equalTo(self.view.mas_width);
        make.height.mas_equalTo(self.view.mas_height);
    }];
    self.photoView.backgroundColor = [UIColor blackColor];
}

- (void)createPhoto{
    self.photoView.contentSize = CGSizeMake(VIEWWIDTH * self.detailArr.count, 0);
    self.photoView.pagingEnabled = YES;
    self.photoView.contentOffset = CGPointMake(VIEWWIDTH * (NSInteger)self.num, 0);
    for (NSInteger i = 0; i < self.detailArr.count ; i++) {
        BaseImageView *imageView = [[BaseImageView alloc]init];
        [self.photoView addSubview:imageView];
        
        [imageView sd_setImageWithURL:[NSURL URLWithString:[[[self.detailArr[i] picturesMarr]lastObject] myPicture]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.photoView).with.offset(VIEWWIDTH * i);
            make.top.equalTo(self.photoView).with.offset(100);
            make.width.equalTo(self.photoView);
            make.height.equalTo(self.photoView).with.offset(-200);
        }];
        BaseView *titleView = [[BaseView alloc]init];
        [imageView addSubview:titleView];
        titleView.backgroundColor = [UIColor blackColor];
        titleView.alpha = 0.5;
        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView);
            make.right.equalTo(imageView);
            make.bottom.equalTo(imageView);
            make.top.equalTo(imageView.mas_bottom).with.offset(-50);
            make.bottom.equalTo(imageView);
        }];
        BaseLabel *titleLabel = [[BaseLabel alloc]init];
        [titleView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(titleView).with.insets(UIEdgeInsetsMake(5, 10, -5, 10));
        }];
        titleLabel.text = [NSString stringWithFormat:@"%@  %ld/%ld",self.titleStr, i+1, self.detailArr.count];
        titleLabel.textColor = [UIColor lightGrayColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
